#ifndef _appBll_H
#define _appBll_H
#include "fclude.h"
#include <db.h>
#include <microhttpd.h>
#include <jansson.h>
#include "MHD_utils.h"
#include "BDB.h"
#include "directoryDB.h"
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

struct system_data {
pthread_mutex_t lock;
struct MHD_Daemon *httpd;
//  struct profile_data profile;
//  struct node_data nodes[NUM_NODES];
 };

/*
 typedef struct appcon_info{
		struct MHD_Connection * connection ;
		const char * url ;
		char *post_data;
	        const char *request_mime_type;
		char * response ;
		const char * method ;
}app_con_info_t ,* app_con_info_p;
*/
typedef int (*handler_func)(struct MHD_Connection *connection, app_con_info_p sysdata, int uri_num);

struct element_handler {
	  char name[MAX_URL_LEN];

	  handler_func get_handler;
	  handler_func post_handler;
	  handler_func put_handler;
	  handler_func del_handler;
};

extern const struct element_handler handler_table[];

int appcon_new(app_con_info_p *pappcon);
int handle_main_request(app_con_info_p pappcon,mr_log_p plog, mr_conf_p pconf);


int list_all_nodes(struct MHD_Connection *connection,app_con_info_p sysdata, int uri_num);
int list_a_node(struct MHD_Connection *connection,app_con_info_p sysdata, int uri_num);
int create_a_node(struct MHD_Connection *connection,app_con_info_p sysdata, int uri_num);
int update_a_node(struct MHD_Connection *connection,app_con_info_p sysdata, int uri_num);
int remove_a_node(struct MHD_Connection *connection,app_con_info_p sysdata, int uri_num);
#endif


